/*=========================================================================

Program:   Virtual Surgery
Language:  C++
Date:      2009-9-1
Version:   0.1
Mail:		   nelfylee@gmail.com

Copyright (c) 2009 Nelfy Lee. All rights reserved.

=========================================================================*/
#ifndef _VIEW2D_H_
#define _VIEW2D_H_

#include "View.h"

#include "vtkActor.h"
#include "vtkActor2D.h"
#include "vtkPolyData.h"
#include "vtkTextActor.h"
#include "vtkLineSource.h"
#include "vtkImageActor.h"
#include "vtkTextMapper.h"
#include "vtkProperty2D.h"
#include "vtkPointPicker.h"
#include "vtkDoubleArray.h"
#include "vtkImageReslice.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkAssignCoordinates.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkImageThreshold.h"
#include "vtkImageMapToWindowLevelColors.h"
#include "vtkImageBlend.h"
#include "vtkSliderWidget.h"
#include "vtkSliderRepresentation2D.h"
#include "vtkInteractorStyleImage.h"
#include "vtkTransform.h"

#include <QLabel>
#include <QSlider>
#include <QComboBox>
#include <QToolButton>

#include "ui_View2dToolbar.h"

class Source;


enum ViewOrientation
{
	voAXIAL = 1,
	voCORONAL,
	voSAGITTAL
};

enum ViewMode
{
	vmNormal,
	vmPickingSeed,
	vmPixelGear
};


typedef struct _seed
{
	int x;
	int y;
	int z;
}SEED;


class View2D : public View
{
	Q_OBJECT
public:
	View2D(const QString &name,int id);
	~View2D();

	void setBaseImage(vtkImageData*);
	void setBaseThreshold(double,double);
	void addBlendingImage(vtkImageData*);
	void removeBlendedImage(vtkImageData*);
	vtkImageData *baseImage();
	QList<vtkImageData*>* imageList();

	void pickSeed();
	void removeSeed(QString);
	void seedSelected(QString);
	QString currentSeed();
	const QStringList& seedList();

	void setDisplayMode(ViewMode mode);

	void setCrossLineEnabled(bool flag);
	bool isCrossLineEnabled();

	ViewMode viewMode();

public slots:
	void slotLeftButtonPressed(vtkObject *obj, unsigned long);
	void slotLeftButtonReleased(vtkObject *obj, unsigned long);
	void slotMouseMove(vtkObject *obj);
	void slotRightButtonPressed(vtkObject *obj);
	void slotRightButtonReleased(vtkObject *obj);
	void slotMouseEnter(vtkObject *obj);
	void slotMouseLeave(vtkObject *obj);

protected:
	virtual void resizeEvent(QResizeEvent *);	//Qt's

private:
	void currEventPos(vtkObject *obj, int pos[3]);
	void initInternalActors();
	void updatePointLabels();
	void showCrossLine(bool flag);
	void enableSliderWidget(bool flag);
	//void setDisplayMode(ViewMode mode);
	void changeSlice(int num);

private slots:
	void slotPostSetMode();
	void slotEnableCrossLine(bool);
	void slotEnableTextInfo(bool);
	void slotSliderMouseMove(vtkObject*);
	void slotViewOrientationChanged(int);

	void slotResetWindowLevel();
	void slotStartWindowLevel(vtkObject *obj);
	void slotChangeSlice(vtkObject* object);

signals:
	void emitSeedPicked();

protected:
	QToolButton *m_btnCrossLine;
	QToolButton *m_btnTextInfo;
	QToolButton *m_btnResetWL;
	QComboBox *m_cbView;

	ViewMode m_viewMode;
	vtkMatrix4x4 *m_resliceAxes;
	ViewOrientation m_viewOrientation;

	QList<vtkImageData*> m_imageList;

	vtkLookupTable *m_blendingLookupTable;
	vtkImageActor *m_baseActor;
	vtkActor2D *m_textActorWindowLevel;
	vtkActor2D *m_textActorIntensityValue;
	vtkTextMapper *m_textMapperWindowLevel;
	vtkTextMapper *m_textMapperIntensityValue;
	vtkImageMapToWindowLevelColors *m_mapperWindowLevel;
	vtkPointPicker *m_pointPicker;
	vtkImageReslice *m_reslicedImage;
	vtkImageBlend *m_blendedImage;
	vtkInteractorStyleImage *m_interactorStyle;
	vtkImageThreshold *m_filterThreshold;

	vtkLineSource *m_sourceCrossLineV;
	vtkLineSource *m_sourceCrossLineH;
	vtkPolyDataMapper2D *m_mapperCrossLineV;
	vtkPolyDataMapper2D *m_mapperCrossLineH;
	vtkActor2D *m_actorCrossLineV;
	vtkActor2D *m_actorCrossLineH;

	int m_poseLeftPressed[3];
	int	m_baseExtent[6];				//base volume
	double m_baseSpacing[3];
	double m_baseOrigin[3];
	double m_baseScalar[2];
	double m_baseWindow;
	double m_baseLevel;
	double m_tempWindow;
	double m_tempLevel;
	QString m_currSeed;
	QStringList m_seedList;

	vtkSliderRepresentation2D *m_sliderRep;
	vtkSliderWidget *m_sliderWidget;
	int *m_sliderPoint1;
	int *m_sliderPoint2;
	int m_sliderValue;
	bool m_currentSliderStatus;


	//////////////////////////////////////////////////////////////////////////
	// Pixel Gear Mode


};

#endif


